package com.everflourish.yeah100.utils.collections;

import com.everflourish.yeah100.entity.NewFriend;
import com.everflourish.yeah100.utils.StringUtil;

import java.util.Comparator;

/**
 * 好友排序
 * 现根据状态排序
 * 3为通过对方添加我为好友的请求 -->1为请求对方添加我为好友--> 0为已通过好友验证-->2为以上两者都不是,
 *
 * @author pf
 * @date 2015-3-16
 */
public class NewFriendCollections implements Comparator<NewFriend> {
    private boolean isDesc = false;

    public NewFriendCollections(boolean isDesc) {
        this.isDesc = isDesc;
    }

    @Override
    public int compare(NewFriend lhsNewFriend, NewFriend rhsNewFriend) {
        int compareFlag = 0;
        int lhsStatus = StringUtil.parseInt(lhsNewFriend.getStatus(), 2);
        int rhsStatus = StringUtil.parseInt(rhsNewFriend.getStatus(), 2);
        if (lhsStatus == 2 && rhsStatus != 2) {
            compareFlag = 1;
        } else if (lhsStatus != 2 && rhsStatus == 2) {
            compareFlag = -1;
        } else {
            compareFlag = lhsStatus - rhsStatus;
        }
        if (isDesc) {
            compareFlag = -compareFlag;
        }
        return compareFlag;
    }
}
